from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-07 14:02:10.735764
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 07, May, 2022
Time: 14:02:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2050
Nobs: 649.000 HQIC: -49.5848
Log likelihood: 7970.38 FPE: 2.29633e-22
AIC: -49.8256 Det(Omega_mle): 2.00109e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325419 0.061438 5.297 0.000
L1.Burgenland 0.105086 0.039138 2.685 0.007
L1.Kärnten -0.110130 0.020520 -5.367 0.000
L1.Niederösterreich 0.195411 0.081681 2.392 0.017
L1.Oberösterreich 0.119750 0.080668 1.484 0.138
L1.Salzburg 0.258285 0.041583 6.211 0.000
L1.Steiermark 0.043463 0.054620 0.796 0.426
L1.Tirol 0.105579 0.044084 2.395 0.017
L1.Vorarlberg -0.063330 0.038955 -1.626 0.104
L1.Wien 0.026281 0.071479 0.368 0.713
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050669 0.131283 0.386 0.700
L1.Burgenland -0.032788 0.083632 -0.392 0.695
L1.Kärnten 0.040394 0.043849 0.921 0.357
L1.Niederösterreich -0.188408 0.174540 -1.079 0.280
L1.Oberösterreich 0.447493 0.172375 2.596 0.009
L1.Salzburg 0.285401 0.088856 3.212 0.001
L1.Steiermark 0.107479 0.116714 0.921 0.357
L1.Tirol 0.313294 0.094200 3.326 0.001
L1.Vorarlberg 0.021716 0.083241 0.261 0.794
L1.Wien -0.036966 0.152738 -0.242 0.809
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190119 0.031506 6.034 0.000
L1.Burgenland 0.090361 0.020070 4.502 0.000
L1.Kärnten -0.007899 0.010523 -0.751 0.453
L1.Niederösterreich 0.247959 0.041886 5.920 0.000
L1.Oberösterreich 0.156302 0.041367 3.778 0.000
L1.Salzburg 0.041371 0.021324 1.940 0.052
L1.Steiermark 0.024842 0.028009 0.887 0.375
L1.Tirol 0.086405 0.022606 3.822 0.000
L1.Vorarlberg 0.054804 0.019976 2.743 0.006
L1.Wien 0.117244 0.036654 3.199 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112505 0.031618 3.558 0.000
L1.Burgenland 0.045575 0.020142 2.263 0.024
L1.Kärnten -0.014224 0.010561 -1.347 0.178
L1.Niederösterreich 0.179915 0.042036 4.280 0.000
L1.Oberösterreich 0.327319 0.041515 7.884 0.000
L1.Salzburg 0.101833 0.021400 4.759 0.000
L1.Steiermark 0.110187 0.028109 3.920 0.000
L1.Tirol 0.097536 0.022687 4.299 0.000
L1.Vorarlberg 0.059602 0.020048 2.973 0.003
L1.Wien -0.021003 0.036785 -0.571 0.568
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115873 0.058889 1.968 0.049
L1.Burgenland -0.043135 0.037514 -1.150 0.250
L1.Kärnten -0.046503 0.019669 -2.364 0.018
L1.Niederösterreich 0.142763 0.078292 1.823 0.068
L1.Oberösterreich 0.159064 0.077321 2.057 0.040
L1.Salzburg 0.283134 0.039857 7.104 0.000
L1.Steiermark 0.053992 0.052354 1.031 0.302
L1.Tirol 0.167159 0.042255 3.956 0.000
L1.Vorarlberg 0.096702 0.037339 2.590 0.010
L1.Wien 0.073216 0.068513 1.069 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059257 0.046418 1.277 0.202
L1.Burgenland 0.030904 0.029570 1.045 0.296
L1.Kärnten 0.051643 0.015504 3.331 0.001
L1.Niederösterreich 0.203850 0.061713 3.303 0.001
L1.Oberösterreich 0.320549 0.060947 5.259 0.000
L1.Salzburg 0.039960 0.031417 1.272 0.203
L1.Steiermark 0.007063 0.041267 0.171 0.864
L1.Tirol 0.129925 0.033307 3.901 0.000
L1.Vorarlberg 0.065286 0.029432 2.218 0.027
L1.Wien 0.092366 0.054004 1.710 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173109 0.055694 3.108 0.002
L1.Burgenland 0.005847 0.035479 0.165 0.869
L1.Kärnten -0.065169 0.018602 -3.503 0.000
L1.Niederösterreich -0.097123 0.074044 -1.312 0.190
L1.Oberösterreich 0.205242 0.073126 2.807 0.005
L1.Salzburg 0.054711 0.037695 1.451 0.147
L1.Steiermark 0.239872 0.049513 4.845 0.000
L1.Tirol 0.500782 0.039962 12.531 0.000
L1.Vorarlberg 0.060044 0.035313 1.700 0.089
L1.Wien -0.074890 0.064796 -1.156 0.248
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148276 0.061796 2.399 0.016
L1.Burgenland 0.005000 0.039366 0.127 0.899
L1.Kärnten 0.060208 0.020640 2.917 0.004
L1.Niederösterreich 0.183153 0.082157 2.229 0.026
L1.Oberösterreich -0.058738 0.081139 -0.724 0.469
L1.Salzburg 0.206995 0.041825 4.949 0.000
L1.Steiermark 0.132678 0.054938 2.415 0.016
L1.Tirol 0.070222 0.044341 1.584 0.113
L1.Vorarlberg 0.143890 0.039182 3.672 0.000
L1.Wien 0.110170 0.071895 1.532 0.125
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378052 0.036324 10.408 0.000
L1.Burgenland -0.001181 0.023139 -0.051 0.959
L1.Kärnten -0.021840 0.012132 -1.800 0.072
L1.Niederösterreich 0.210932 0.048292 4.368 0.000
L1.Oberösterreich 0.225620 0.047693 4.731 0.000
L1.Salzburg 0.039005 0.024585 1.587 0.113
L1.Steiermark -0.013865 0.032293 -0.429 0.668
L1.Tirol 0.095490 0.026063 3.664 0.000
L1.Vorarlberg 0.053238 0.023031 2.312 0.021
L1.Wien 0.036695 0.042260 0.868 0.385
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036221 0.112981 0.173223 0.141388 0.101872 0.084626 0.038721 0.209930
Kärnten 0.036221 1.000000 -0.021533 0.134237 0.052300 0.089783 0.441442 -0.060670 0.092426
Niederösterreich 0.112981 -0.021533 1.000000 0.322927 0.129622 0.285657 0.075282 0.160932 0.296018
Oberösterreich 0.173223 0.134237 0.322927 1.000000 0.221626 0.309918 0.169037 0.149732 0.249405
Salzburg 0.141388 0.052300 0.129622 0.221626 1.000000 0.131472 0.096656 0.114431 0.129916
Steiermark 0.101872 0.089783 0.285657 0.309918 0.131472 1.000000 0.139050 0.119229 0.049569
Tirol 0.084626 0.441442 0.075282 0.169037 0.096656 0.139050 1.000000 0.069552 0.148651
Vorarlberg 0.038721 -0.060670 0.160932 0.149732 0.114431 0.119229 0.069552 1.000000 0.006665
Wien 0.209930 0.092426 0.296018 0.249405 0.129916 0.049569 0.148651 0.006665 1.000000